package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.YiyaoMapper;
import work.xiaohong.gupiao.pojo.Yiyao;
import work.xiaohong.gupiao.service.YiyaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class YiyaoServiceImpl implements YiyaoService {

    @Autowired
    private YiyaoMapper yiyaoMapper;


    /**
     * 条件+分页查询Yiyao
     * @param yiyao 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Yiyao> findPage(Yiyao yiyao, int page, int size){
        // 构建查询条件
        QueryWrapper<Yiyao> queryWrapper = new QueryWrapper<Yiyao>(yiyao);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return yiyaoMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Yiyao
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Yiyao> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return yiyaoMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Yiyao
     * @param yiyao
     * @return
     */
    @Override
    public List<Yiyao> findList(Yiyao yiyao){
        // 构建查询条件
        QueryWrapper<Yiyao> queryWrapper = new QueryWrapper<Yiyao>(yiyao);
        // 查询数据
        return yiyaoMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Yiyao
     * @param id
     */
    @Override
    public void delete(Integer id){
        yiyaoMapper.deleteById(id);
    }

    /**
     * 根据ID修改Yiyao
     * @param yiyao
     */
    @Override
    public void update(Yiyao yiyao){
        yiyaoMapper.updateById(yiyao);
    }

    /**
     * 增加Yiyao
     * @param yiyao
     */
    @Override
    public void add(Yiyao yiyao){
        yiyaoMapper.insert(yiyao);
    }

    /**
     * 根据ID查询Yiyao
     * @param id
     * @return
     */
    @Override
    public Yiyao findById(Integer id){
        return  yiyaoMapper.selectById(id);
    }

    /**
     * 查询全部Yiyao数据
     * @return
     */
    @Override
    public List<Yiyao> findAll() {
        return yiyaoMapper.selectList(null);
    }
}
